<template>
  <dv-border-box-8 style="width: 600px;margin-top: 50px;">

    <div>
      <el-form :model="formData" ref="formData" name="basic" label-width="120px" autocomplete="off">
        <el-form-item label="企业名称:" name="compName" label-width="120px">
          <!-- <el-input v-if="isCurrent" v-model="formData.compName" /> -->
          <span style="color: white;">{{ formData.compName }}</span>
        </el-form-item>

        <el-form-item label="备注:" name="remark" label-width="120px">
          <el-input v-if="isCurrent && user.userId == 'formData.compName'" v-model="formData.remark"
            type="textarea" :rows="4" />
          <span v-else>{{ formData.remark }}</span>
        </el-form-item>

        <el-form-item label="管理员回复:" name="reply" label-width="120px">
          <el-input v-if="isCurrent && user.roleName!= 'company' " v-model="formData.reply"
            type="textarea" :rows="4" />
          <span v-else>{{ formData.reply }}</span>
        </el-form-item>

        <el-form-item v-if="isCurrent" label="上传材料:" name="fileName" label-width="120px">
          <el-upload class="upload-demo" drag action="https://jsonplaceholder.typicode.com/posts/"
            multiple>
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          </el-upload>
        </el-form-item>

        <el-form-item label="材料下载:" name="remark" label-width="120px">
          <span style="color: white;" @click="clickDownload">{{ formData.fileName||'无' }}</span>
        </el-form-item>

      </el-form>
      <div style="display: flex;align-items: center;justify-content: center;"
        v-if="isCurrent && user.roleName!= 'company'">
        <el-button @click="clickAuditNg" type="danger" size="mini">审核不通过</el-button>
        <el-button type="success" @click="clickAuditOk" size="mini">审核通过</el-button>
      </div>
      <div style="display: flex;align-items: center;justify-content: center;"
        v-if="isCurrent && user.userId == formData.compName">
        <el-button @click="clickSave" type="danger" size="mini">保存</el-button>
        <el-button @click="clickSubmit" type="danger" size="mini">提交审核</el-button>
      </div>

    </div>
  </dv-border-box-8>
</template>
<script>
import {
  auditCompLifeDetail,
  submitCompLifeDetail,
} from '@/service/compLifeDetail';
import { downloadFile } from '@/common/download';
import { getCurrUser } from '@/common/constants';

export default {
  props: ['serverData', 'isCurrent'],
  data() {
    return {
      user: {},
      isCurrentUser: false,
      isEdit: false,
      formData: { compName: '323728973' },
    };
  },
  methods: {
    clickAuditNg() {
      this.clickSaveAudit('N');
    },
    clickAuditOk() {
      this.clickSaveAudit('Y');
    },
    async clickSaveAudit(isNg) {
      const res = await auditCompLifeDetail({ ...this.formData, isNg });
      if (res.success) {
        this.$router.replace({ name: 'board' });
      }
    },
    async clickSave() {
      // const res = await auditCompLifeDetail({ ...this.formData, isNg });
      // if (res.success) {
      //   this.$router.replace({ name: 'board' });
      // }
    },

    async clickSubmit() {
      const res = await submitCompLifeDetail({ ...this.formData });
      if (res.success) {
        this.$emit('refresh');
      }
    },

    clickDownload() {
      if (formData.fileUrl) {
        downloadFile(formData.fileUrl);
      }
    },
  },
  watch: {
    serverData(newVal, oldVal) {
      Object.assign(this.formData, newVal);
    },
  },
  mounted() {
    this.isEdit = true;
    this.user = getCurrUser();
  },
};
</script>
<style scoped>
>>> .el-form-item__content {
  text-align: start;
}
>>> .el-form-item {
  margin-bottom: 10px;
}
</style>